﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                double d1 = double.Parse(textnumber1.Text);
                double d2 = double.Parse(textnumber2.Text);
                string op = combo1.SelectedItem.ToString();
                double result = 0.0;
                switch (op)
                {
                    case "+":
                        result = d1 + d2;
                        break;
                    case "-":
                        result = d1 - d2;
                        break;
                    case "*":
                        result = d1 * d2;
                        break;
                    case "/":
                        if (d2 != 0)
                        {
                            result = d1 / d2;
                        }
                        else
                        {
                            MessageBox.Show("除数不能为0！！");
                        }
                        break;
                    default:
                        break;
                }
                if (op == "/" && d2 == 0)
                {
                    label1.Text = "结果：错误";
                }
                else
                {
                    label1.Text = $"结果：{result}";
                }
            }
            catch (FormatException)//输入检测
            {
                MessageBox.Show("请输入有效的数字！！");
                label1.Text = "结果：无效输入";
            }
        } 
    }
}
